package com.hangoverstudios.batterysaver;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Toast;
import com.hangoverstudios.batterysaver.R;
import com.startapp.android.publish.StartAppSDK;

public class PowerSaveSettingsActivity extends Activity {
	
	Helper helper;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		StartAppSDK.init(this, "109026838", "202627762", true);
		setContentView(R.layout.powers);
		
		helper = new Helper(this);
		
		CheckBox wifi,bluetooth,brightness,dataconnection,vibration;
		
		wifi = (CheckBox)findViewById(R.id.checkBox_wifi);
	    bluetooth = (CheckBox)findViewById(R.id.checkBox_bluetooth);
	    brightness = (CheckBox)findViewById(R.id.checkBox_brightness);
	    dataconnection = (CheckBox)findViewById(R.id.checkBox_dataconnection);
	    vibration = (CheckBox)findViewById(R.id.checkBox_Vibration);
	    
	    wifi.setChecked(helper.isWifiSaverEnabled());
	    bluetooth.setChecked(helper.isBTSaverEnabled());
	    brightness.setChecked(helper.isBrightnessSaverEnabled());
	    dataconnection.setChecked(helper.isMobileDataSaverEnabled());
	    vibration.setChecked(helper.isVibrationSaverEnabled());
	    
	    if(Utils.getDeviceAndroidVersion(getApplicationContext()) > 20)
	    {
	    	dataconnection.setVisibility(View.GONE);
	    }
	   
		
	       wifi.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			@Override
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				// TODO Auto-generated method stub
				
				helper.saveWifiSaverEnabled(isChecked);
				
			}
		   });
	       
	       bluetooth.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					// TODO Auto-generated method stub
					
					helper.saveBTSaverEnabled(isChecked);
				}
			});
	       brightness.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					// TODO Auto-generated method stub
					helper.saveBrightnessSaverEnabled(isChecked);
				}
			});
	       vibration.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					// TODO Auto-generated method stub
					helper.saveVibrationSaverEnabled(isChecked);
				}
			});
	      
			
	       dataconnection.setOnCheckedChangeListener(new OnCheckedChangeListener() {
				
				@Override
				public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
					// TODO Auto-generated method stub
					helper.saveMobileDataSaverEnabled(isChecked);
					
					
				 }
			  });
	}
	public void savebutton (View v)
	{	
		Toast.makeText(getApplicationContext(), "Saved Successfully", Toast.LENGTH_SHORT).show();
		Intent i = new Intent(getApplicationContext(),MainActivity.class);
		startActivity(i);
		finish();
		
	}

   @Override
   public void onBackPressed() 
   {
	   finish();
   }
   }
